package com.xuecheng.content.api;

import com.xuecheng.content.model.dto.SaveOrUpdateTeachPlanDto;
import com.xuecheng.content.model.dto.TeachplanDto;
import com.xuecheng.content.service.TeachplanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author luhao
 * @ClassName TeachplanController.java
 * @Description 课程计划控制器
 * @createTime 2023/5/24
 */
@RestController
@Api(tags = "课程计划api")
public class TeachplanController {
    @Autowired
    private TeachplanService teachplanService;
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    @ApiOperation("根据课程Id查询课程计划")
    public List<TeachplanDto> findTeachPlanByTreeNodes(@ApiParam(value = "课程计划Id",required = true) @PathVariable Long courseId){
        List<TeachplanDto> teachplanDtos = teachplanService.queryTeachPlanByTreeNodes(courseId);
        return teachplanDtos;
    }
    @ApiOperation("添加或修改课程计划信息")
    @PostMapping("/teachplan")
    public void saveOrUpdateTeachPlan(@RequestBody SaveOrUpdateTeachPlanDto dto){
        teachplanService.addOrAmendTeachPlan(dto);
    }
    @ApiOperation("删除课程计划")
    @DeleteMapping("/teachplan/{coursePlanId}")
    public void dropTeachPlanById(@ApiParam(value = "课程计划id",required = true)@PathVariable Long coursePlanId){
        teachplanService.removeTeachPlanById(coursePlanId);
    }
    @ApiOperation("课程计划向上移动")
    @PostMapping("/teachplan/moveup/{courseId}")
    public void moveUpCoursePlan(@ApiParam(value = "课程计划id",required = true)@PathVariable Long courseId) {
        teachplanService.moveUpTeachPlanById(courseId);
    }
    @ApiOperation("课程计划下移")
    @PostMapping("/teachplan/movedown/{courseId}")
    public void moveDownCoursePlan(@ApiParam(value = "课程计划id",required = true)@PathVariable Long courseId){
        teachplanService.moveDownTeachPlanById(courseId);
    }
}
